<script setup lang="ts">
import { useUserStore } from "@/stores/userStore";
import { isDark } from "@/utils/isDark";
//导入用户store
const useStroe = useUserStore();
//获取用户信息状态
const { userinfo } = storeToRefs(useStroe);
//引入路由
const router = useRouter();
const route = useRoute();
//定义选中变量
const pather = ref(route.path);

async function Change(url: string) {
  await router.push({
    path: url,
  });
  pather.value = route.path;
}
</script>
<template>
  <div class="body">
    <aside>
      <div class="slogan">
        <img src="@/assets/img/logo.png" alt="" />
      </div>
      <ul>
        <li @click="Change('/')">首页</li>
        <li
          :class="{ active: pather === '/backend' }"
          @click="Change('/backend')"
        >
          个人中心
        </li>
        <li
          :class="{ active: pather === '/backend/MessageBoard' }"
          @click="Change('/backend/MessageBoard')"
        >
          留言板
        </li>
        <li
          :class="{ active: pather === '/backend/userActions' }"
          @click="Change('/backend/userActions')"
        >
          头像列表
        </li>
        <li
          :class="{ active: pather === '/backend/covers' }"
          @click="Change('/backend/covers')"
        >
          文章封面
        </li>
        <li
          v-if="userinfo.result.is_superuser"
          :class="{ active: pather === '/backend/add_article' }"
          @click="Change('/backend/add_article')"
        >
          添加文章
        </li>
      </ul>
    </aside>
    <router-view></router-view>
  </div>
</template>

<style scoped lang="scss">
main {
  padding: 20px;
  box-sizing: border-box;
  width: calc(100% - 200px);
  height: 100vh;
  background-color: var(--el-bg-color);
}
.body {
  display: flex;
  position: relative;
}
aside {
  width: 200px;
  height: 100vh;
  background-color: #808595;
  .slogan {
    margin-top: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
    img {
      width: 80%;
    }
  }
  & > ul {
    width: 100%;
    margin-top: 40px;
    .active {
      background-color: rgba(0, 0, 0, 0.2);
    }
    & > li {
      color: white;
      width: 100%;
      height: 40px;
      justify-content: center;
      display: flex;
      align-items: center;
      transition: all 0.3s;
      cursor: pointer;
      &:hover {
        background-color: rgba(0, 0, 0, 0.2);
      }
    }
  }
}
</style>
